---

- name: Install Nginx
  ansible.builtin.dnf:
    name: nginx
    state: latest
    
- name: Add Consul template integration. Add nginx template configuration
  ansible.builtin.copy:
    src: nginx.conf.ctmpl
    dest: "{{ default_consul_template_location }}/nginx.ctmpl"
  when: lb_nginx_with_consul_template == true
    
- name: Add Consul template integration. Add cosul template configuration
  ansible.builtin.copy:
    src: lb-templates.hcl
    dest: /etc/consul-template.d/lb-templates.hcl
  when: lb_nginx_with_consul_template == true

- name: Restart Consul template service
  ansible.builtin.service:
    name: consul-template
    daemon_reload: true
    state: restarted
  when: lb_nginx_with_consul_template == true

- name: Enable and restart Nginx
  ansible.builtin.service:
    name: nginx
    daemon_reload: true
    state: restarted
    enabled: yes
